﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

using LoomDataEmulator.Core;
using LoomDataEmulator.Data;
using LoomDataEmulator.Logger;
using LoomDataEmulator.Console.Properties;
using System.Timers;

namespace LoomDataEmulator.Console
{
    class Program
    {
        
        static void Main(string[] args)
        {
            System.Console.WriteLine("LoomDataEmulator version 1.0b");
            System.Console.WriteLine("Type 'exit' to quit");
            
            System.Console.Write("Setting up database...");
            DatabaseSchemaCreator.CreateTestDatabaseEnvironment("loomdataemulator", ".");
            System.Console.WriteLine("done.");
            System.Console.Write("Setting initial timer interval");
            Timer t = new Timer();
            t.Interval = Settings.Default.SchedulerDefaultTimer;
            t.Enabled = true;
            System.Console.WriteLine("done.");

            System.Console.Write("Initiating emulator...");
            var loomDataServer = new LoomDataServer(new CmiDaiInputProcessor(), new Scheduler(t));

            //inputProcessor in this case will be the scheduled task
            ((Scheduler)loomDataServer.Scheduler).RegisterNewTask((IScheduledTask)loomDataServer.ProcessInput);

            System.Console.WriteLine("done.");

            string inputFolder = Settings.Default.ConsoleInputFolder;
            string outputFolder = Settings.Default.ConsoleOutputFolder;
            
            loomDataServer.ListenPath(inputFolder);
            System.Console.WriteLine(String.Format("Now listening to folder {0}", inputFolder));

            string command = null;

            do
            {
                System.Console.Write("> ");
                command = System.Console.ReadLine();
                
            } while (command != "exit");

        }
    }
}
